package com.x_memteor.base_master.utils.power;

import java.lang.reflect.InvocationTargetException;

public class Utils {
    public static void setValueToProp(String key, String val) {
        try {
            Class<?> classType = Class.forName("android.os.SystemProperties");
            classType.getDeclaredMethod("set", new Class[]{String.class, String.class}).invoke(classType, new Object[]{key, val});
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e2) {
            e2.printStackTrace();
        } catch (InvocationTargetException e3) {
            e3.printStackTrace();
        } catch (Exception e4) {
            e4.printStackTrace();
        }
    }

    public static String getValueFromProp(String key) {
        String value = "";
        try {
            Class<?> classType = Class.forName("android.os.SystemProperties");
            return (String) classType.getDeclaredMethod("get", new Class[]{String.class}).invoke(classType, new Object[]{key});
        } catch (Exception e) {
            return value;
        }
    }

    public static boolean validate(int year, int month, int day, int hourOfDay, int minute) {
        if ((year > 2099 && year < 2017) || month < 0 || month > 11) {
            return false;
        }
        int[] monthLengths = new int[]{31, 31, -1, 31, 30, 31, 30, 31, 31, 30, 31, 30};
        if (isLeapYear(year)) {
            monthLengths[2] = 29;
        } else {
            monthLengths[2] = 28;
        }
        int monthLength = monthLengths[month];
        if (day < 1 || day > monthLength || hourOfDay < 0 || hourOfDay > 23 || minute < 0 || minute > 59) {
            return false;
        }
        return true;
    }

    private static boolean isLeapYear(int year) {
        return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
    }
}